package com.zh.ssmshirofreemarker.controller;


import com.alibaba.fastjson.JSONObject;
import com.zh.ssmshirofreemarker.Utils.ResponseUtil;
import com.zh.ssmshirofreemarker.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZH
 * @since 2018-07-24
 */
@Controller
@RequestMapping("/userRole")
public class UserRoleController {

    @Autowired
    IUserRoleService userRoleService;

    @ResponseBody
    @RequestMapping(method=RequestMethod.POST)
    public ResponseUtil bindRole(Long userId,String roleIds){
        List<Long> list = JSONObject.parseArray(roleIds,Long.class);
        boolean result = false;
        try{
          result = userRoleService.bindRoles(userId,list);
        } catch (Exception e){
            e.printStackTrace();
        }
        return ResponseUtil.check(result);
    }

}

